using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Components.Portal;
using NCS.Library.Components.Security;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Zones;

namespace NCS.Module.CMS.Admin
{
    public partial class TCSettings : AuthenticatedControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tr_footer.Visible = false;

            if (!Page.IsPostBack)
            {
                dropTaiChinh.DataSource = PortalController.GetPortalsByLang(AppEnv.GetLanguage());
                dropTaiChinh.DataBind();
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            //tai chinh
            dropChungKhoan.Items.Clear();
            dropChuyengiaPT.Items.Clear();
            dropTieuDiem.Items.Clear();
            dropTinmoiNong.Items.Clear();
            dropDocnhieunhat.Items.Clear();
            drophothome.Items.Clear();
         
            //
            dropTCMoiNong.Items.Clear();
            dropTC_MoiNong_Position1.Items.Clear();

            dropTCCK.Items.Clear();
            dropTC_CK_Position1.Items.Clear();

            dropTCCGPT.Items.Clear();
            dropTC_CGPT_Position1.Items.Clear();

            dropTCTieuDiem.Items.Clear();
            dropTC_TieuDiem_Position1.Items.Clear();
            
            txtFooter.HTMLValue = ConvertUtility.ToString(Portal[Constants.CMS_Footer + AppEnv.GetLanguage()]);

            //tai chinh
            int ptc = ConvertUtility.ToInt32(Portal[Constants.CMS_PortalTC + AppEnv.GetLanguage()]);
            if (ptc > 0)
            {
                MiscUtility.SelectItemFromList(dropTaiChinh, ptc.ToString());
            }
            else
            {
                MiscUtility.SelectItemFromList(dropTaiChinh, ConvertUtility.ToString(Request.QueryString["portalid"]));
            }
            ZoneController.LoadZones(dropTinmoiNong.Items, dropTaiChinh.SelectedValue);
            
            foreach (ListItem item in dropTinmoiNong.Items)
            {
                dropTieuDiem.Items.Add(new ListItem(item.Text, item.Value));
                dropChuyengiaPT.Items.Add(new ListItem(item.Text, item.Value));
                dropChungKhoan.Items.Add(new ListItem(item.Text, item.Value));
                dropDocnhieunhat.Items.Add(new ListItem(item.Text, item.Value));
                drophothome.Items.Add(new ListItem(item.Text, item.Value));

                //trang cap 2 va chi tiet
                dropTCMoiNong.Items.Add(new ListItem(item.Text, item.Value));
                dropTC_MoiNong_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropTCCK.Items.Add(new ListItem(item.Text, item.Value));
                dropTC_CK_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropTCCGPT.Items.Add(new ListItem(item.Text, item.Value));
                dropTC_CGPT_Position1.Items.Add(new ListItem(item.Text, item.Value));

                dropTCTieuDiem.Items.Add(new ListItem(item.Text, item.Value));
                dropTC_TieuDiem_Position1.Items.Add(new ListItem(item.Text, item.Value));
            }

            int TC_hothome = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_HotHome + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(drophothome, TC_hothome.ToString());

            int TC_newest = ConvertUtility.ToInt32(Portal[Constants.CMS_TinMoiNong + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTinmoiNong, TC_newest.ToString());

            int TC_focus = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_TieuDiem + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTieuDiem, TC_focus.ToString());

            int TC_Chuyengia = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_Chuyengia + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropChuyengiaPT, TC_Chuyengia.ToString());

            int TC_Chungkhoan = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_Chungkhoan + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropChungKhoan, TC_Chungkhoan.ToString());

            int TC_Docnhieunhat = ConvertUtility.ToInt32(Portal[Constants.CMS_TC_Docnhieunhat + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropDocnhieunhat, TC_Docnhieunhat.ToString());

            //trang cap 2 va chi tiet

            // tin moi nong
            int Level2_TC_TinMoiNong = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TC_TinMoiNong + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTCMoiNong, Level2_TC_TinMoiNong.ToString());

            int CMS_Level2_TinMoiNong_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_TC_TinMoiNong + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTC_MoiNong_Position1, CMS_Level2_TinMoiNong_Position1.ToString());

            //tin thi truong chung khoan
            int Level2_TC_CK = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TC_CK + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTCCK, Level2_TC_CK.ToString());

            int CMS_Level2_CK_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_TC_CK + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTC_CK_Position1, CMS_Level2_CK_Position1.ToString());

            //chuyen gia phan tich
            int CMS_Level2_CGPT = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TC_CGPT + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTCCGPT, CMS_Level2_CGPT.ToString());

            int CMS_Level2_CGPT_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_CGPT + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTC_CGPT_Position1, CMS_Level2_CGPT_Position1.ToString());

            //tieu diem
            int CMS_Level2_TC_TieuDiem = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TC_TieuDiem + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTCTieuDiem, CMS_Level2_TC_TieuDiem.ToString());

            int CMS_Level2_TieuDiem_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_TC_TieuDiem + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTC_TieuDiem_Position1, CMS_Level2_TieuDiem_Position1.ToString());


        }
       
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                PortalSetting.SetValue(Constants.CMS_TinMoiNong + AppEnv.GetLanguage(), dropTinmoiNong.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TC_Chungkhoan + AppEnv.GetLanguage(), dropChungKhoan.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TC_Chuyengia + AppEnv.GetLanguage(), dropChuyengiaPT.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TC_TieuDiem + AppEnv.GetLanguage(), dropTieuDiem.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_PortalTC + AppEnv.GetLanguage(), dropTaiChinh.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TC_Docnhieunhat + AppEnv.GetLanguage(), dropDocnhieunhat.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TC_HotHome + AppEnv.GetLanguage(), drophothome.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Footer + AppEnv.GetLanguage(), txtFooter.HTMLValue);

                //trang cap 2 va chi tiet
                PortalSetting.SetValue(Constants.CMS_Level2_TC_TinMoiNong + AppEnv.GetLanguage(), dropTCMoiNong.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTCMoiNong.SelectedValue + "_" + AppEnv.GetLanguage(), dropTC_MoiNong_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_TC_CK + AppEnv.GetLanguage(), dropTCCK.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTCCK.SelectedValue + "_" + AppEnv.GetLanguage(), dropTC_CK_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_TC_CGPT + AppEnv.GetLanguage(), dropTCCGPT.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTCCGPT.SelectedValue + "_" + AppEnv.GetLanguage(), dropTC_CGPT_Position1.SelectedValue);

                PortalSetting.SetValue(Constants.CMS_Level2_TC_TieuDiem + AppEnv.GetLanguage(), dropTCTieuDiem.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTCTieuDiem.SelectedValue + "_" + AppEnv.GetLanguage(), dropTC_TieuDiem_Position1.SelectedValue);
                

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

      
    }
}